package com.lightsh.joint;

import org.jbox2d.common.Vec2;
import org.jbox2d.dynamics.Body;
import org.jbox2d.dynamics.World;
import org.jbox2d.dynamics.joints.Joint;
import org.jbox2d.dynamics.joints.RevoluteJoint;
import org.jbox2d.dynamics.joints.RevoluteJointDef;

public class LRevoluteJoint extends BaseJoint{
	protected RevoluteJointDef mRevoluteJointDef;
	protected RevoluteJoint mRevoluteJoint;
	public LRevoluteJoint(World world, Body body1, Body body2, Vec2 anchor){		
		mWorld = world;
		mRevoluteJointDef = new RevoluteJointDef();
		mJointDef = mRevoluteJointDef;
		mRevoluteJointDef.initialize(body1, body2, anchor);
	}
	
	public LRevoluteJoint setMotor(boolean enableMotor, float maxMotorTorque, float motorSpeed){
		if(mRevoluteJoint == null){
			mRevoluteJointDef.enableMotor = enableMotor;
			mRevoluteJointDef.maxMotorTorque = maxMotorTorque;
			mRevoluteJointDef.motorSpeed = motorSpeed;
		}else{
			mRevoluteJoint.m_enableMotor = enableMotor;
			mRevoluteJoint.m_maxMotorTorque = maxMotorTorque;
			mRevoluteJoint.m_motorSpeed = motorSpeed;
		}
		return this;
	}
	
	public LRevoluteJoint setLimit(boolean enableLimit, float lowerAngle, float upperAngle){
		if(mRevoluteJoint == null){
			mRevoluteJointDef.enableLimit = enableLimit;
			mRevoluteJointDef.lowerAngle = lowerAngle;
			mRevoluteJointDef.upperAngle = upperAngle;
		}else{
			mRevoluteJoint.m_enableLimit = enableLimit;
			mRevoluteJoint.m_lowerAngle = lowerAngle;
			mRevoluteJoint.m_upperAngle = upperAngle;
		}
		return this;
	}

	@Override
	public void create() {
		super.create();
		mRevoluteJoint = (RevoluteJoint) mJoint;
	}

	@Override
	public RevoluteJoint getJoint() {
		return mRevoluteJoint;
	}
	
	
}
